﻿using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace prjKQXS_DLL.Dal
{
    public class PhanQuyenForm_DAL
    {
        private SqlDataAdapter dAd = null;
        private SqlConnection conn = null;
        private SqlCommand cmd = null;
        public void XulyQuyenCT(string Tacvu1, string Tacvu2, string IID, string Nhom, int ID)
        {
            conn = new SqlConnection(BienTc.connString);
                try
                {
                    conn.Open();
                    {
                        cmd = new SqlCommand("proc_URList_Xuly", conn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@ID", ID);
                        cmd.Parameters.AddWithValue("@IName", Tacvu1);
                        cmd.Parameters.AddWithValue("@INameE", Tacvu2);
                        cmd.Parameters.AddWithValue("@IID", IID);
                        cmd.Parameters.AddWithValue("@Nhom", Nhom);
                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception)
                {
                    throw;
                }
        }
        
        public DataTable LoadPhanQuyenTL(string DK, int isPublic)
        {
            conn = new SqlConnection(BienTc.connString);
            {
                conn.Open();
                dAd = new SqlDataAdapter("select * from [UR_list] Where Ucha =0 AND isPublic =" + isPublic + DK, conn);
                DataSet dSet = new DataSet();
                try
                {
                    dAd.Fill(dSet, "UR_listTable");
                    return dSet.Tables["UR_listTable"];
                }
                catch
                {
                    throw;
                }
                finally
                {
                    dSet.Dispose();
                    dAd.Dispose();
                    conn.Close();
                    conn.Dispose();
                }
            }
        }
        
        public DataTable LoadKhuVuc()
        {
            conn = new SqlConnection(BienTc.connString);
            {
                conn.Open();
                dAd = new SqlDataAdapter("SELECT distinct IID, IName from UR_list Where Ucha =1 Order by IID", conn);
                DataSet dSet = new DataSet();
                try
                {
                    dAd.Fill(dSet, "KhuVucTable");
                    return dSet.Tables["KhuVucTable"];
                }
                catch
                {
                    throw;
                }
                finally
                {
                    dSet.Dispose();
                    dAd.Dispose();
                    conn.Close();
                    conn.Dispose();
                }
            }
        }
        
    }
}
